<?php

declare(strict_types=1);

namespace app\controller\sys;

use think\facade\View;

use app\utils\ReUtils;
use app\model\Industry as IndustryModel;

/**
 * +----------------------------------------------------------------------
 * 行业应用控制制器
 * @author huwhis@163.com
 * @version   0.0.1
 * +----------------------------------------------------------------------
 */
class Industry extends Base
{
    protected $modelName = "Industry";

    public function index()
    {
        $list = IndustryModel::queryPage();

        View::assign('list', $list);

        return View::fetch();
    }

    public function save($id = 0)
    {
        if ($this->app->request->isPost()) {
            $params = $this->app->request->param();

            $params['content'] =  isset($params['content']) ? $params['content'] : '';
            $params['keywords'] = str_replace(' ', '', $params['keywords']);

            $id = $params['id'];
            unset($params['id']);

            try {
                if ($id != 0) {
                    IndustryModel::where('id', $id)->update($params);
                } else {
                    $data = IndustryModel::create($params);
                }
                return ReUtils::success();
            } catch (\Exception $e) {
                $msg = $e->getMessage();

                return ReUtils::error("错误提示:" . $msg);
            }
        } else {
            if ($id) {
                $data = IndustryModel::find($id);
            } else {
                $data = new IndustryModel();
            }
            View::assign('data', $data);
        

            return View::fetch();
        }
    }
}
